import mongoose from 'mongoose'

import config from '../config'

const db = mongoose.createConnection(config.mongo, { autoIndex: false })

db.on('open', () => {
  console.log('MongoDB Connect Success')
})

db.on('error', err => {
  console.error('MongoDB Connect Error: ', err.toString())
  process.exit(1)
})

const ObjectId = mongoose.Schema.Types.ObjectId

const Schema = mongoose.Schema
export {
  ObjectId,
  db,
  Schema,
}
